package com.oceansoft.core.interceptor;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class RegisterVerifyInterceptor implements HandlerInterceptor {

	private int regStartTime;
	private int regEndTime;

	@Override
	public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {

	}

	@Override
	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
			throws Exception {

	}

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {
		SimpleDateFormat sdf = new SimpleDateFormat("HH");
		int curr_hour = Integer.valueOf(sdf.format(new Date()));
		if (curr_hour >= regStartTime && curr_hour <= regEndTime) {
			return true;
		}
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		response.getWriter().write("已经超出注册时间~");
		return false;
	}

	public int getRegStartTime() {
		return regStartTime;
	}

	public void setRegStartTime(int regStartTime) {
		this.regStartTime = regStartTime;
	}

	public int getRegEndTime() {
		return regEndTime;
	}

	public void setRegEndTime(int regEndTime) {
		this.regEndTime = regEndTime;
	}

}
